//
//  NameViewController.m
//  Light
//
//  Created by 骁唐 on 15/9/7.
//  Copyright (c) 2015年 骁唐. All rights reserved.
//

#import "NameViewController.h"
#import "UserConfig.h"

@interface NameViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *nameText;
@property (weak, nonatomic) IBOutlet UIImageView *backGround;

@end

@implementation NameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.nameText.delegate = self;
    self.nameText.returnKeyType = UIReturnKeyDone;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark 点击空白处，隐藏键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.nameText resignFirstResponder];
}

#pragma mark -
#pragma mark return按钮处理
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.nameText resignFirstResponder];
    [self goToNext];//下一个界面跳转
    return YES;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark -
#pragma mark 导航返回按钮
- (IBAction)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark 下一步按钮点击
- (IBAction)nextClick {
    [self goToNext];//进行下一个界面跳转
}
#pragma mark -
#pragma mark 跳转到下一个界面
- (void)goToNext
{
    [self.view endEditing:YES];
    if (self.nameText.text.length == 0)
    {
        TJJALERT_VIEW(@"江湖名称很重要，不能为空呦");
    }
    else
    {
        UserConfig *userconfig = [UserConfig sharingUserConfig];
        [userconfig setCurrentNickName:self.nameText.text];
        [self performSegueWithIdentifier:@"nameToGender" sender:nil];
    }
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    //SXW__标记，设置背景
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200) {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }

}

@end
